<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div  class="head-top">
        <el-form size="small" label-width="70px" v-formkey="{query:toQuery}">
          <el-row :gutter="10">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="业务日期">
                <div class="flex flex-row">
                  <el-date-picker
                    v-model="query.startTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="开始日期"
                  />
                  <el-date-picker
                    v-model="query.endTime"
                    align="right"
                    unlink-panels
                    class="fl1"
                    format="yyyy - MM - dd "
                    value-format="yyyy-MM-dd"
                    default-value
                    range-separator=""
                    placeholder="结束日期"
                  />
                </div>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="编码">
                <el-input  v-model="query.code"></el-input>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="拣货人">
                <!--<el-input  v-model="query.pickUserName"></el-input>-->
                <zSelect :value.sync="query.pickUserId" url="api/dropDown/sysUserList" :params="{businessAttr:'8'}"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="客户">
                <zSelect :value.sync="query.customerId" url="api/dropDown/basCustomerList" :params="{businessAttr:'3'}"
                         style="width:  100%"/>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="10" style="text-align: center">
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="出库仓库">
                <zSelect :value.sync="query.warehouseId" url="api/dropDown/basWarehouseList" />
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="打印状态">
                <el-select
                  v-model="query.isPrint"
                  class="filter-item"
                  clearable
                  placeholder="打印状态"
                  size="small"
                  style="width: 100%"
                  @change="toQuery"
                >
                  <el-option
                    v-for="item in dict.common_yes_or_no"
                    :key="item.id"
                    :label="item.label"
                    :value="item.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-form-item label="备注">
                <el-input v-model="query.remark" placeholder="输入备注进行搜索"/>
              </el-form-item>
            </el-col>
            <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
              <el-button class="filter-item"  size="mini" type="primary" @click="toQuery">搜索</el-button>
              <el-button class="filter-item" plain   size="mini" type="primary"
                         @click="resetQuery()">重置</el-button>
            </el-col>
          </el-row>
        </el-form>
      </div>
    <crudOperation :permission="permission" style="margin-top: 60px">
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="primary"
        @click="toPicking(crud.selections)"
        v-permission="permission.pickStart"
      >
        开始拣货
      </el-button>
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="success"
        :disabled="crud.selections.length !== 1"
        @click="isDisabled"
        v-permission="permission.pickEnd"
      >拣货完成
      </el-button>
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="success"
        :disabled="crud.selections.length=== 0"
        @click="pickEndBatch"
        v-permission="permission.onePickEnd"
      >一键拣货完成
      </el-button>
      <el-button
        slot="left"
        class="filter-item"
        size="mini"
        type="primary"
        @click="crud.toDetail('wareSalesInvoicePickDetail',crud.selections[0].id)"
        v-permission="permission.checkEnd"
      >
        集货完成
      </el-button>
<!--      <el-button-->
<!--        slot="left"-->
<!--        class="filter-item"-->
<!--        size="mini"-->
<!--        type="success"-->
<!--        :disabled="crud.selections.length !== 1"-->
<!--        @click="cancelPickS"-->
<!--      >取消拣货-->
<!--      </el-button>-->
<!--      <el-button-->
<!--        slot="left"-->
<!--        class="filter-item"-->
<!--        size="mini"-->
<!--        type="success"-->
<!--        :disabled="crud.selections.length !== 1"-->
<!--        @click="handleSetPickSeq()"-->
<!--      >优先级修改-->
<!--      </el-button>-->
<!--      <el-button-->
<!--        slot="left"-->
<!--        class="filter-item"-->
<!--        size="mini"-->
<!--        type="success"-->
<!--        :disabled="crud.selections.length !== 1"-->
<!--        @click="toAssignPickUser"-->
<!--      >指定拣货人-->
<!--      </el-button>-->
      <el-button
        slot="right"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-notebook-2"
        :disabled="crud.selections.length < 1"
        @click="tabInvoiceType('pickPrint',0)"
        v-permission="permission.pickPrint"
      >拣货小票打印</el-button>
      <el-button
        slot="right"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-notebook-2"
        :disabled="crud.selections.length < 1"
        v-permission="permission.pickPrint"
        @click="tabInvoiceType('pickPrint',1)"
      >拣货小票打印预览</el-button>
      <el-button
        slot="right"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-notebook-2"
        :disabled="crud.selections.length < 1"
        @click="tabInvoiceType('checkPrint',0)"
        v-permission="permission.checkPrint"
      >核对小票打印</el-button>
      <el-button
        slot="right"
        class="filter-item"
        size="mini"
        type="warning"
        icon="el-icon-notebook-2"
        :disabled="crud.selections.length < 1"
        v-permission="permission.checkPrint"
        @click="tabInvoiceType('checkPrint',1)"
      >核对小票打印预览</el-button>
      <el-button
        slot="right"
        class="filter-item"
        @click="removeStorage"
        size="mini"
        type="warning">
        清除打印缓存</el-button>
    </crudOperation>
<!--      状态切换  -->
      <el-tabs v-model="query.pickStatus" @tab-click="handleClickPickStatus">
        <el-tab-pane label="未拣货" name="0"></el-tab-pane>
        <el-tab-pane label="拣货中" name="1"></el-tab-pane>
        <el-tab-pane label="拣货完成" name="2"></el-tab-pane>
        <el-tab-pane label="集货完成" name="3"></el-tab-pane>
        <el-tab-pane label="装车完成" name="4"></el-tab-pane>
        <el-tab-pane label="全部" name="-1"></el-tab-pane>
      </el-tabs>
      <div>
        <el-form  size="small" :model="form" ref="form" :rules="rules" class="content">
          <el-form-item label="" class="left">
            <zSelect :value.sync="form.pickUserId" placeholder="请选择拣货人" url="api/dropDown/sysUserList" :params="{businessAttr:'8'}"/>
          </el-form-item>
          <el-form-item label=""  class="center">
          </el-form-item>
          <el-form-item label=""  class="right">
          </el-form-item>
        </el-form>
      </div>

      <div class="content">
        <div class="left oldDiv">


          <!--表格渲染-->
          <el-table ref="table"  border
                    height="600"
                    show-summary
                    @cell-dblclick="row=>crud.toEdit(row)"
                    v-loading="crud.loading"
                    :data="crud.data"
                    size="small"
                    style="width: 100%;"
                    v-if="isShowTable"
                    @header-dragend="changeColWidth"
                    @contextmenu.native="showMenu"
                    :summary-method="crud.sumRow"
                    @row-click="crud.selectRow"
                    :row-style="crud.rowClass"
                    :row-class-name="crud.tableRowClassName"
                    @selection-change="crud.selectionChangeHandler"
          >
            <el-table-column :render-header="crud.renderHeader" type="selection" width="60" />
            <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
            <el-table-column

              v-if="item.visible"
              v-for="(item, index) in crud.header"
              :key="`col_${index}`"
              :prop="item.prop"
              :label="columnLabel(item)"
              :width="item.width + 'px'"
              :data-porp='item.prop'
              @contextmenu.native="showMenu"
              @header-dragend="changeColWidth"
            >
              <!-- 自定义渲染模版 -->
              <template slot-scope="scope">
                <!-- 当列key为 sort 时，渲染一个手柄icon -->
                <template v-if="item.prop =='sort'">
                  <div class="handle_move">
                    <i :class="scope.row['sort']" />
                  </div>
                </template>
                <template v-else>
                  <span v-if="item.type == 1" style="margin-left: 10px">{{scope.row[`${item.prop}`]}}</span>
                  <span v-if="item.type == 2" style="margin-left: 10px">{{ parseTime(scope.row[`${item.prop}`])}}</span>
                  <span v-if="item.type == 3" style="margin-left: 10px">{{ getDict(`this.dict.label.${item.dictionary}["${scope.row[item.prop]}"]`) }}</span>
                </template>
              </template>
            </el-table-column>
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('busDate')" prop="busDate" label="业务日期">-->
<!--              <template slot-scope="scope">-->
<!--                <span>{{ parseTime(scope.row.busDate) }}</span>-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="单据编码" />-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="线路" />-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickSeq')" prop="pickSeq" label="拣货优先级" width="100"/>-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickStatus')" prop="pickStatus" label="拣货状态" >-->
<!--              <template slot-scope="scope">-->
<!--                <el-tag>{{ dictName(dict.t_ware_sales_invoice_pick_status,scope.row.pickStatus)  }}</el-tag>-->
<!--              </template>-->
<!--            </el-table-column>-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickUserName')" prop="pickUserName" label="拣货人" />-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('warehouseName')" prop="warehouseName" label="仓库" />-->
<!--            <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注" />-->
          </el-table>
        </div>
        <div class="right oldDiv">
          <!--数据-->
          <div class="infoMation">
            <div class="infoMation-item">
              <span>共有</span><span>{{Number(infoData.unPickNum) + Number(infoData.pickingNum)+ Number(infoData.pickEndNum)+Number(infoData.checkEndNum)+Number(infoData.loadEndNum)}}条</span>
            </div>
            <div class="infoMation-item">
              <span>未拣货条数</span><span>{{infoData.unPickNum}}条</span>
            </div>
            <div class="infoMation-item">
              <span>拣货中条数</span><span>{{infoData.pickingNum}}条</span>
            </div>
            <div class="infoMation-item">
              <span>拣货完成条数</span><span>{{infoData.pickEndNum}}条</span>
            </div>
            <div class="infoMation-item">
              <span>集货完成条数</span><span>{{infoData.checkEndNum}}条</span>
            </div>
            <div class="infoMation-item">
              <span>装车完成条数</span><span>{{infoData.loadEndNum}}条</span>
            </div>
          </div>
          <PieChart :infoData="infoData"/>
        </div>
      </div>
      <pagination/>
    </div>
<!--   开始拣货 -->
    <el-dialog :close-on-click-modal="false" title="开始拣货"
               :visible.sync="isPick"  append-to-body width="80vw">
      <el-form size="small" :model="form" ref="form" :rules="rules"  label-width="70px" >
      <el-col :xs="24" :sm="12" :md="8" :lg="6" :xl="6">
        <el-form-item label="拣货人" prop="pickUserId">
          <zSelect :value.sync="form.pickUserId" url="api/dropDown/sysUserList"
                   :params="{businessAttr:'8'}"   style="width:  100%;margin-bottom: 0px"/>
        </el-form-item>
      </el-col>
      <el-table ref="table" stripe border v-loading="crud.loading" :data="pickList" height="400" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column :render-header="crud.renderHeader" type="index" width="60" label="序号"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('busDate')" prop="busDate" label="业务日期">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.busDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('code')" prop="code" label="编码" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('name')" prop="name" label="线路" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerAreaName')" prop="customerAreaName" label="区域" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('customerName')" prop="customerName" label="客户" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickSeq')" prop="pickSeq" label="拣货优先级" width="100"/>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickStatus')" prop="pickStatus" label="拣货状态" >
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.busDate) }}</span>
          </template>
        </el-table-column>
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('goodsCount')" prop="goodsCount" label="数量" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('boxCount')" prop="boxCount" label="箱数" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('packBoxCount')" prop="packBoxCount" label="装箱箱数" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('pickPrintCount')" prop="pickPrintCount" label="打印次数" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('checkPrintCount')" prop="checkPrintCount" label="核对打印次数" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('count')" prop="count" label="条数" />
        <el-table-column :render-header="crud.renderHeader" v-if="columns.visible('remark')" prop="remark" label="备注" />
        </el-table>
        <div class="fotter">
            <el-pagination
              @size-change="handleSizeChange"
              @current-change="handleCurrentChange"
              :page-sizes="[10, 20, 30, 40]"
              :page-size="100"
              style="margin-top: 20px;"
              class="fotter-left"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total">
            </el-pagination>
          <div class="fotter-right">
            <el-button type="text" @click="closedDialog()">取消</el-button>
            <el-button type="primary" @click="submitCU">确认</el-button>
          </div>
        </div>
      </el-form>
    </el-dialog>
    <el-dialog  title="打印预览"
                destroy-on-close
                v-dialogDrag
                close-on-press-escape
                :visible.sync="showPdf" append-to-body width="50vw">
      <j-pdf :src="pdfSrc" ></j-pdf>
    </el-dialog>
    <vue-context-menu :contextMenuData="contextMenuData"
                      @tableConfig="tableConfig"
                      @deletedata="deletedata"></vue-context-menu>

    <!-- 表格配置 -->
    <el-dialog title="表格配置"
               :visible.sync="tableConfigShow"
               width="60%">
      <j-table-column-config :columns.sync="crud.header"  @tabSave="tabSave" @pit="pit" />
    </el-dialog>
<!--    指定拣货人-->
    <el-dialog :close-on-click-modal="false" title="指定拣货人"
               :visible.sync="isPickUser"  append-to-body width="30vw">
      <el-form size="small" :model="form" ref="form" :rules="rules"  label-width="70px" >
          <el-form-item label="拣货人" prop="pickUserId">
            <zSelect :value.sync="form.pickUserId" url="api/dropDown/sysUserList"
                     style="width:  100%;margin-bottom: 0px" :params="{businessAttr:'8'}"/>
          </el-form-item>
      </el-form>
      <div class="fotters">
        <el-button type="text" @click="closedUserDialog()">取消</el-button>
        <el-button type="primary" @click="submitUserCU">确认</el-button>
      </div>
    </el-dialog>
    <!--   优先级修改-->
    <el-dialog :close-on-click-modal="false" title="优先级修改"
               :visible.sync="isPickSep"  append-to-body width="30vw">
      <el-form size="small" :model="form" ref="form" :rules="rules"  label-width="70px" >
          <el-form-item label="级别" prop="pickSeq">
            <el-input-number v-model="form.pickSeq"  style="width:  100%;margin-bottom: 0px"  :min="1" :max="10" label="请选择"></el-input-number>
          </el-form-item>
      </el-form>
      <div class="fotters">
        <el-button type="text" @click="isPickSep = false">取消</el-button>
        <el-button type="primary" @click="submitSepCU">确认</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="请选择打印模板"
      :visible.sync="pringDialog"
      width="30%"
    >
      <jPrintConfig groupId="salesOrderInvoice"
                    v-if="pringDialog"
                    @getPrintId="print"
                    :isPreview="0"
      ></jPrintConfig>
    </el-dialog>
  </div>
</template>

<script>
import crudWareSalesInvoicePick from '@/api/erp/wareSalesInvoicePick'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import PieChart from  '@/components/Echarts/PieChart'
import jPrintConfig from "../../../components/jPrintConfig/jPrintConfig";
import {tablemixins} from "@/mixins/tablemixins";
import jTableColumnConfig from "@/components/jTableColumnConfig/jTableColumnConfig";
import { publicListKey } from "@/utils/key";
import { batchPickEnd } from '../../../api/erp/wareSalesInvoice'
// crud交由presenter持有
const defaultCrud = CRUD({ title: '发货单',name:'wareSalesInvoicePick', url: 'api/wareSalesInvoicePick', sort: 't.pickSeq,desc|code,desc', optShow: {
    add: false,
    edit: false,
    del: false,
    download: true,
    downloadDetail:true,
    leadingIn: true,
    enable: false,
    disable: false,
    reject: false,
    pass: false
  },  query:{
    lineIds: null,
    customerTypeIds:null,
    pickStatus:'0'
  }, crudMethod: { ...crudWareSalesInvoicePick }})
const defaultForm = { id: null, code: null, name: null, type: null, saleType: null, busDate: null, receiveDate: null, sourceType: null, sourceId: null, sourceCode: null, serialNumber: null, customerOrderCode: null, customerId: null, customerCode: null, customerName: null, isContact: null, customerAreaId: null, customerAreaCode: null, customerAreaName: null, customerTypeId: null, customerTypeCode: null, customerTypeName: null, pCustomerId: null, pCustomerCode: null, pCustomerName: null, mCustomerId: null, mCustomerCode: null, mCustomerName: null, sCustomerId: null, sCustomerCode: null, sCustomerName: null, deptId: null, deptCode: null, deptName: null, userId: null, userCode: null, userName: null, warehouseId: null, warehouseCode: null, warehouseName: null, count: null, boxCount: null, taxAmount: null, noTaxAmount: null, tax: null, discountAmount: null, isCancelPick: null, pickStatus: null, pickSeq: null, pickUserId: null, pickUserCode: null, pickUserName: null, pickStartTime: null, pickEndTime: null, pickBoxCount: null, pickTaxAmount: null, pickNoTaxAmount: null, pickTax: null, isPickPrint: null, pickPrintCount: null, checkUserId: null, checkUserCode: null, checkUserName: null, checkTime: null, checkBoxCount: null, checkTaxAmount: null, checkNoTaxAmount: null, checkTax: null, isCheckPrint: null, checkPrintCount: null, isLoad: null, loadTime: null, loadOrderId: null, loadOrderCode: null, carId: null, carCode: null, carName: null, driverUserId: null, driverUserCode: null, driverUserName: null, followUserId: null, followUserIds: null, followUserCode: null, followUserName: null, packBoxCount: null, isPrint: null, printCount: null, seq: null, orderStatus: null, remark: null, orderRemark: null, createUserId: null, createUserCode: null, createUserName: null, createTime: null, updateUserId: null, updateUserCode: null, updateUserName: null, updateTime: null, auditUserId: null, auditUserCode: null, auditUserName: null, auditTime: null, closeUserId: null, closeUserCode: null, closeUserName: null, closeTime: null }
export default {
  name: 'WareSalesInvoice',
  components: { pagination, crudOperation, rrOperation, udOperation,PieChart, jPrintConfig, jTableColumnConfig },
  mixins: [presenter(defaultCrud), header(), form(defaultForm), crud(), publicListKey, tablemixins],
  dicts: ['common_yes_or_no','t_ware_sales_invoice_pick_status','t_ware_sales_invoice_sale_type','t_ware_sales_invoice_type',
    't_ware_sales_invoice_source_type','t_bas_customer_is_contact','common_order_status'
  ],
  data() {
    return {
      pickerOptions: {
        shortcuts: [{
          text: '最近一周',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近一个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
            picker.$emit('pick', [start, end]);
          }
        }, {
          text: '最近三个月',
          onClick(picker) {
            const end = new Date();
            const start = new Date();
            start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
            picker.$emit('pick', [start, end]);
          }
        }]
      },
      rules: {
        pickUserId: [
          { required: true, message: '拣货人不能为空', trigger: 'blur' }
          ],
        pickSeq: [
          { required: true, message: '级别不能为空', trigger: 'blur' }
        ],
      },
      showPdf:false,
      pdfSrc:'',
      permission: {
        add: ['admin', 'wareSalesInvoicePick:add'],
        edit: ['admin', 'wareSalesInvoicePick:edit'],
        del: ['admin', 'wareSalesInvoicePick:del'],
        import: ['admin', 'wareSalesInvoicePick:import'],
        export: ['admin', 'wareSalesInvoicePick:export'],
        copy: ['admin', 'wareSalesInvoicePick:copy'],
        upload: ['admin', 'wareSalesInvoicePick:upload'],
        download: ['admin', 'wareSalesInvoicePick:download'],
        pass: ['admin', 'wareSalesInvoicePick:pass'],
        reject: ['admin', 'wareSalesInvoicePick:reject'],
        closed: ['admin', 'wareSalesInvoicePick:closed'],
        invalid: ['admin', 'wareSalesInvoicePick:invalid'],
        stop: ['admin', 'wareSalesInvoicePick:stop'],
        recover: ['admin', 'wareSalesInvoicePick:recover'],
        pickStart: ['admin', 'wareSalesInvoicePick:pickStart'],
        pickEnd: ['admin', 'wareSalesInvoicePick:pickEnd'],
        checkEnd: ['admin', 'wareSalesInvoicePick:checkEnd'],
        cancelPick: ['admin', 'wareSalesInvoicePick:cancelPick'],
        pickPrint: ['admin', 'wareSalesInvoicePick:pickPrint'],
        checkPrint: ['admin', 'wareSalesInvoicePick:checkPrint'],
        setPickSeq: ['admin', 'wareSalesInvoicePick:setPickSeq'],
        assignPickUser: ['admin', 'wareSalesInvoicePick:assignPickUser'],
        onePickEnd: ['admin', 'wareSalesInvoicePick:onePickEnd'],

      },
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      basLineList:[], //线路
      areaList: [], // 区域
      props: {
        label: 'name',
        children: 'zones'
      },
      activeName: 'first',
      pickStatus: 0,
      search: null,
      count: 1,
      filterArea: '',
      filterBas: '',
      selectTypes: [],
      isPick: false,
      customerTypeIds:null,
      lineIds: null,
      pickList: [],
      total:0,
      page:1,
      size:10,
      isPickUser: false,
      isPickSep: false,
      infoData: null,
      pringDialog:false
    }
  },
  updated() {
    this.$nextTick(() => {
      this.$refs.table.doLayout()
    })
  },
  watch: {
    filterArea(val) {
      this.$refs.treeArea.filter(val);
    },
    filterBas(val) {
      this.$refs.treeBas.filter(val);
    }
  },
  created() {
    this.basLine()
    this.getInfo()
  },
  methods: {
    tabInvoiceType(val,isPreview){
      this.invoiceType = val
      this.preView(isPreview)
    },
    toQuery(){
      this.getInfo()
      this.crud.toQuery()
    },
    resetQuery(){
      this.getInfo()
      this.crud.resetQuery()
    },

    getValue(e){
      this.query.startTime =this.query.dataExtent[0]
      this.query.endTime =this.query.dataExtent[1]
    },
    // 获取信息
    getInfo(){
      crudWareSalesInvoicePick.info(this.query).then(res => {
        this.infoData = res.data
      }).catch((res)=>{
      })
    },
    isDisabled(){
      if(this.crud.selections[0].pickStatus !== 0){
        this.crud.toDetail('wareSalesInvoicePickDetail',this.crud.selections[0].id)
      }else {
        this.$message({
          type:"error",
          message:'未开始拣货不允许拣货完成'
        })
      }
    },
    //指定拣货人
    submitUserCU(){
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        let ids = []
        let data ={pickUserId:this.form.pickUserId,ids:this.crud.selections.map(item => item.id)}
        console.log('ids',ids)
        crudWareSalesInvoicePick.assignPickUser(data).then(res => {
          console.log('content',res)
          this.$message({
            type: 'success',
            message: '指定拣货人成功!'
          });
          this.isPickUser = false
          this.crud.toQuery()
        }).catch((res)=>{
        })
      })
    },

    preView(val){
      this.isPreview = val
      this.pringDialog = true
    },
    print(val){
      if(val !== null){
        this.pringDialog=false
        localStorage.setItem(this.invoiceType,val)
        this.printIds = this.crud.selections.map(item=>item.id)
        alert(this.isPreview)
        this.crud.doPrint(val,this.printIds,this.isPreview,this.invoiceType)
        this.crud.toQuery()
      }else {
        this.$message.error('请选择打印模板');
      }
    },
    removeStorage(){
      localStorage.removeItem('pickPrint')
      localStorage.removeItem('checkPrint')
      this.$message({
        message: '清除缓存成功',
        type: 'success'
      })
    },

    submitSepCU(){
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        let ids = []
        let data ={pickSeq:this.form.pickSeq,ids:this.crud.selections.map(item => item.id)}
        console.log('ids',ids)
        crudWareSalesInvoicePick.setPickSeq(data).then(res => {
          console.log('content',res)
          this.$message({
            type: 'success',
            message: '设置拣货优先级成功!'
          });
          this.isPickUser = false
          this.crud.toQuery()
        }).catch((res)=>{
        })
      })
    },
    // 优先级修改
    handleSetPickSeq(){
      this.isPickSep = true
    },
    // 取消拣货
    cancelPickS(){


      this.$confirm('此操作将取消拣货, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let data = {
          ids: this.crud.selections.map(item => item.id)
        }
        crudWareSalesInvoicePick.cancelPick(data).then(res => {
          this.$message({
            type: 'success',
            message: '取消成功!'
          });
          this.crud.toQuery()
        }).catch((res)=>{
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '取消成功'
        });
      });
    },
    pickEndBatch(){
      const check = this.crud.selections.every(val=>val.pickStatus)
      if (check){
        const ids = this.crud.selections.map(item=>item.id)
        batchPickEnd(ids).then(res=>{
          if (res.status === 200){
            this.$message.success('拣货成功')
            this.crud.refresh()
          }else {
            this.$message.error(res.msg)
          }

        })
      }else {
        this.$message.success('请检查状态单据是否开始拣货')
      }
    },
    // 指定拣货人
    toAssignPickUser(){
      this.isPickUser = true
      // crudWareSalesInvoice.assignPickUser({pickStatus:'0',sort:'pick_seq desc',page:this.page,size:this.size}).then(res => {
      //   console.log('content',res)
      //   this.pickList = res.data.content
      //   this.total = res.data.totalElements
      //   this.isPick = true
      // }).catch((res)=>{
      // })
    },
    // 开始拣货
    toPicking(row){
      if(!this.form.pickUserId){
        this.$message({
          type: 'error',
          message: '请先选择拣货人!'
        });
        return false
      }
      this.submitCU()
      // crudWareSalesInvoicePick.list({pickStatus:'0',sort:'pick_seq desc',page:this.page,size:this.size}).then(res => {
      //   console.log('content',res)
      //   this.pickList = res.data.content
      //   this.total = res.data.totalElements
      //   this.isPick = true
      // }).catch((res)=>{
      // })
    },
    // 關閉 拣货列表
    closedUserDialog(){
      this.isPickUser = false
    },
    // 關閉 拣货列表
    closedDialog(){
      this.pickList = []
      this.total = 0
      this.isPick = false
    },
    // 开始拣货01
    submitCU(){
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        let ids = []
        // this.pickList.map((item) => {
        //   ids.push(Number(item.id))
        // })
        if(this.crud.selections.length>0){
          this.crud.selections.map((item) => {
            ids.push(Number(item.id))
          })
        }else{
          ids.push(Number(this.crud.data[0].id))
        }
        // setTimeout(()=>{this.pickPrint(ids)},1000)
        let data ={pickUserId:this.form.pickUserId,ids:ids}
        console.log('ids',ids)
        crudWareSalesInvoicePick.pickStart(data).then(res => {
          console.log('content',res)
          this.$message({
            type: 'success',
            message: '开始拣货成功!'
          });
          this.isPreview = 0
          this.pickPrint(ids)
          this.toQuery()
          this.isPick = false
        }).catch((res)=>{
        })
      })
    },
    pickPrint(list){
      console.log(list)
      const printTemplate = localStorage.getItem('pickPrint')
      this.printIds = this.crud.selections.map(item=>item.id)
      if (printTemplate){
        this.crud.doPrint(printTemplate,list,this.isPreview,"pickPrint")
      }else {
        this.invoiceType = 'pickPrint'
        this.printIds = list
        this.pringDialog = true
      }
    },
    handleSizeChange(val) {
      this.size = val
      this.toPicking()
      console.log(`每页 ${val} 条`);
    },
    handleCurrentChange(val) {
      this.page = val
      this.toPicking()
      console.log(`当前页: ${val}`);
    },
    handleCheckChange(data, checked, indeterminate) {
      console.log(data, checked, indeterminate);
      const rows = this.$refs.treeBas.getCheckedNodes()
      if (rows.length == 0) {
        return false
      }
      this.selectTypes = rows.map(r => r.id)
      this.query.customerAreaIds = this.selectTypes.join(',')
      this.crud.toQuery()
      console.log('selectTypes', this.selectTypes)
      this.getGoodsList()
    },
    handleCheckLineChange(data, checked, indeterminate) {
      console.log(data, checked, indeterminate);
      const rows = this.$refs.treeArea.getCheckedNodes()
      if (rows.length == 0) {
        return false
      }
      this.selectTypes = rows.map(r => r.id)
      this.query.lineIds = this.selectTypes.join(',')
      this.crud.toQuery()
      this.getGoodsList()
    },
    handleClickPickStatus(){
      this.query.lineIds = ''
      this.crud.selections = []
      this.query.customerAreaIds = ''
      this.crud.toQuery()
    },
    filterNode(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    filterNodeLine(value, data) {
      if (!value) return true;
      return data.name.indexOf(value) !== -1;
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }, // 新增与编辑前做的操作
    [CRUD.HOOK.afterToCU](crud, form) {
    },
    handleClick(tab, event) {
      if(this.activeName == 'first'){
        this.basLine()
      }else{
        this.getArea()
      }
    },
    basLine(name){
      crudWareSalesInvoicePick.basLineList({name}).then(res => {
        this.basLineList = res.content
      }).catch((res)=>{
      })
    },
    getArea(name){
      crudWareSalesInvoicePick.childBasCustomerAreaList({name}).then(res => {
          this.areaList = res.content
      }).catch((res)=>{
      })
    },
  }
}
</script>

<style lang="scss" rel="stylesheet/scss" scoped>
//.head-container{
//  margin-top: 300px;
//}
.head-top{
  position: fixed;
  background: #ffffff;
  top: 85px;
  z-index: 99!important;
}
  .table-img {
    display: inline-block;
    text-align: center;
    background: #ccc;
    color: #fff;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
    vertical-align: middle;
    width: 32px;
    height: 32px;
    line-height: 32px;
  }
  .content{
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    .left{
      width: 60%;
      //margin-top: 11px;
      .top{
        margin-bottom: 10px;
      }
    }
    .right{
      width: 35%;
    }
  }
  .fotter{
    display: flex;
    align-items: center;
    height: 50px;
    line-height: 50px;
    margin-top: 20px;
    justify-content: space-between;
    .fotter-left{
      width: 50%;
      display: inline-block;
    }
    .fotter-right{
      width: 50%;
      text-align: right;
      display: inline-block;
    }
  }
  .fotters{
    width: 100%;
    text-align: center;
  }
  .infoMation{
    width: 100%;
    margin-bottom: 20px;
    .infoMation-item{
      display: flex;
      padding:  0 15%;
      align-items: center;
      justify-content: space-between;
      font-size: 16px;
      color: #6d6b6b;
      margin-bottom: 10px;
    }
  }
</style>
